from datetime import datetime
from apps.common.utils.decrypt import *


def response_success_notScrypt(data):
    return {
        "code": 10000,
        "data": data,
        "message": "sucess"
    }


def response_success(data):
    # print('success', data)
    return {
        "code": 10000,
        "data": aesEncrypt(AESKey, data),
        "message": "sucess"
    }


def response_error(error):
    print('error', error)
    return {
        "code": 9999,
        "message": error
    }


def response_message(message):
    print('message', message)
    return {
        "code": 8888,
        "message": message
    }


def response_modalMessage(message):
    print('modalMessage', message)
    return {
        "code": 7777,
        "message": message
    }


def response_action(code, message):
    print('action', code, message)
    return {
        "code": code,
        "message": message,
    }


# 8888 提示错误
# 9999 系统异常


# 1001 配对成功


# 获取请求参数方法
def getRequestParams(request, isDecrypt=True):
    params = {}
    if request.method == "GET" or request.method == "DELETE":
        params = request.query_params.dict()
    elif request.method == "POST" or request.method == "PUT":
        if isDecrypt:
            if request.data and request.data.get('data'):
                params = aesDecrypt(AESKey, request.data.get('data'))
            else:
                params = {}
        else:
            params = request.data

    if request.user != 'AnonymousUser':
        if request.user.id:
            params['requestUserId'] = request.user.id
            params['requestUsername'] = request.user.username

    if request.headers.get('build'):
        params['build'] = request.headers.get('build')

    if params.get('channel'):
        params['channel'] = params.get('channel')
    elif request.headers.get('channel'):
        params['channel'] = request.headers.get('channel')

    if params.get('clientname'):
        params['clientname'] = params.get('clientname')
    elif request.headers.get('clientname'):
        params['clientname'] = request.headers.get('clientname')

    print("---------------接收的参数" + request.path + "-----------------", params)

    return params


def getRequestParamsNotHeader(request):
    params = {}
    if request.method == "GET" or request.method == "DELETE":
        params = request.query_params.dict()
    elif request.method == "POST" or request.method == "PUT":
        params = aesDecrypt(AESKey, request.data)
    print("----------------接收的参数------------------------", params)

    return params
